home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / lstFindFrom.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-19  |  1.7 KB  |  69 lines

  1. /*-
  2.  * LstFindFrom.c --
  3.  *    Find a node on a list from a given starting point. Used by Lst_Find.
  4.  *
  5.  * Copyright (c) 1988 by University of California Regents
  6.  *
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appears in all copies.  Neither the University of California nor
  11.  * Adam de Boor makes any representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15. #ifndef lint
  16. static char *rcsid =
  17. "$Id: lstFindFrom.c,v 1.6 88/11/17 20:52:37 adam Exp $ SPRITE (Berkeley)";
  18. #endif lint
  19.  
  20. #include    "lstInt.h"
  21.  
  22. /*-
  23.  *-----------------------------------------------------------------------
  24.  * Lst_FindFrom --
  25.  *    Search for a node starting and ending with the given one on the
  26.  *    given list using the passed datum and comparison function to
  27.  *    determine when it has been found.
  28.  *
  29.  * Results:
  30.  *    The found node or NILLNODE
  31.  *
  32.  * Side Effects:
  33.  *    None.
  34.  *
  35.  *-----------------------------------------------------------------------
  36.  */
  37. LstNode
  38. Lst_FindFrom (l, ln, d, cProc)
  39.     Lst                  l;
  40.     register LstNode    ln;
  41.     register ClientData d;
  42.     register int    (*cProc)();
  43. {
  44.     register ListNode    tln;
  45.     Boolean        found = FALSE;
  46.     
  47.     if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
  48.     return (NILLNODE);
  49.     }
  50.     
  51.     tln = (ListNode)ln;
  52.     
  53.     do {
  54.     if ((*cProc) (tln->datum, d) == 0) {
  55.         found = TRUE;
  56.         break;
  57.     } else {
  58.         tln = tln->nextPtr;
  59.     }
  60.     } while (tln != (ListNode)ln && tln != NilListNode);
  61.     
  62.     if (found) {
  63.     return ((LstNode)tln);
  64.     } else {
  65.     return (NILLNODE);
  66.     }
  67. }
  68.  
  69.